﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Mrc.Domain.Module.ConfigCenter
{ 
    public class MasterHealthCheckTask : IHostedService, IDisposable
    {
        private Timer _timer;
        public MasterHealthCheckTask(){ }

        public Task StartAsync(CancellationToken cancellationToken)
        {
            _timer = new Timer(DoWork, null, TimeSpan.Zero,TimeSpan.FromSeconds(10));
            return Task.CompletedTask;
        }
        private async void DoWork(object state)
        {
            try
            {

            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error:{ex.Message}");
            }
            await Task.FromResult("");
        }
        public Task StopAsync(CancellationToken cancellationToken)
        {
            _timer?.Change(Timeout.Infinite, 0);
            return Task.CompletedTask;
        }
        public void Dispose()
        {
            _timer?.Dispose();
        }
    }
}
